function drawChart1(c1){
	var option = {	    
	    title:{
			text:'门急诊收入',
			x:'center',
			textStyle:{
				color:'#fff',
				fontSize:'14px'
			}
		},
	    tooltip : {
	        trigger: 'axis',
	        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
	            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '0',
	        containLabel: true
	    },
	    xAxis : [
	        {
	            type : 'category',
	            splitLine:{show: false},//去除网格线
	            data : ['其他', '药费', '化验', '材料', '挂诊', '检查', '治疗'],
	            axisTick: {
	                alignWithLabel: true
	            },
	            axisLine:{
	            	lineStyle:{
	            		color:'#fff',
	            		fontSize:'12px'
	            	}
	            }
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value',
	            splitLine:{show: false},//去除网格线
	            axisLine:{
	            	lineStyle:{
	            		color:'#fff',
	            		fontSize:'12px'
	            	}
	            }
	        }
	    ],
	    series : [
	        {
	            name:'门急诊收入',
	            type:'bar',
	            barWidth: '60%',
	            data:[18517301.09, 16873157.15, 2779194.5, 1948909, 23914, 19141, 0],
	            itemStyle: {
	                normal: {
	                    color: new echarts.graphic.LinearGradient(
		                    0, 0, 0, 1,
		                    [
		                        {offset: 0, color: 'rgba(20,200,212,1)'},
		                        {offset: 0.2, color: 'rgba(20,200,212,0.5)'},
		                        {offset: 1, color: 'rgba(20,200,212,0.1)'}
		                    ]
		                )
	                }
	            }
	        }
	    ]
	};
	c1.setOption(option);
}

function drawChart2(c2){
	var option = {
	    title:{
			text:'住院收入',
			x:'center',
			textStyle:{
				color:'#fff',
				fontSize:'14px'
			}
		},
	    tooltip : {
	        trigger: 'axis',
	        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
	            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        }
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '0',
	        containLabel: true
	    },
	    xAxis : [
	        {
	            type : 'category',
	            splitLine:{show: false},//去除网格线
	            data : ['床位', '材料', '药费', '其他', '护理', '诊疗', '化验','手术','检查','治疗'],
	            axisTick: {
	                alignWithLabel: true
	            },
	            axisLine:{
	            	lineStyle:{
	            		color:'#fff',
	            		fontSize:'12px'
	            	}
	            }
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value',
	            splitLine:{show: false},//去除网格线
	            axisLine:{
	            	lineStyle:{
	            		color:'#fff',
	            		fontSize:'12px'
	            	}
	            }
	        }
	    ],
	    series : [
	        {
	            name:'门急诊收入',
	            type:'bar',
	            barWidth: '60%',
	            data:[89160614.34, 43919914.5, 43561734.71, 27480960.9, 13268929, 10978662.88, 9852161.3,4921209,456723.15,2.5],
	            itemStyle: {
	                normal: {
	                    color: new echarts.graphic.LinearGradient(
		                    0, 0, 0, 1,
		                    [
		                        {offset: 0, color: 'rgba(20,200,212,1)'},
		                        {offset: 0.2, color: 'rgba(20,200,212,0.5)'},
		                        {offset: 1, color: 'rgba(20,200,212,0.1)'}
		                    ]
		                )
	                }
	            }
	        }
	    ]
	};
	c2.setOption(option);
}

function drawChart3(c3){
	var category = [];
	var lineData = [];   //数据通过下边两个随机数获得的
	
	var dottedBase = +new Date();
	for (var i = 0; i < 31; i++) {
	    var date = new Date(dottedBase += 3600 * 24 * 1000);
	    category.push([
	        date.getFullYear(),
	        date.getMonth(),
	        date.getDate()
	    ].join('-'));
	    var b = Math.random() * 200;
    	var d = Math.random() * 200;
    	lineData.push(parseInt(d + b));
	}

	var option = {
	    title:{
	    	text:'预约人次统计',
	    	x:'left',
	    	textStyle:{
				color:'#fff',
				fontSize:'16px'
			}
	    },
	    tooltip: {
	        axisPointer: {
	            type: 'shadow'
	        }
	    },
	    xAxis: {
	        data: category,
	        axisLine: {
	            lineStyle: {
	                color: '#fff'
	            }
	        }
	    },
	    yAxis: {
	        splitLine: {show: false},
	        axisLine: {
	            lineStyle: {
	                color: '#fff'
	            }
	        }
	    },
	    series: [{
	        name: 'line',
	        type: 'line',
	        smooth: true,
	        showAllSymbol: true,
	        symbol: 'emptyCircle',
	        symbolSize: 10,
	        data: lineData
	    },
	    {
	        name: 'line',
	        type: 'bar',
	        barGap: '-100%',
	        barWidth: 10,
	        itemStyle: {
	            normal: {
	                color: new echarts.graphic.LinearGradient(
	                    0, 0, 0, 1,
	                    [
	                        {offset: 0, color: 'rgba(20,200,212,0.5)'},
	                        {offset: 0.2, color: 'rgba(20,200,212,0.2)'},
	                        {offset: 1, color: 'rgba(20,200,212,0)'}
	                    ]
	                )
	            }
	        },
	        z: -12,
	        data: lineData
	    }]
	};
	c3.setOption(option);
}

function drawRadiusChart(chartObj,rdData){
	var option = {
	    title: {
	        text: rdData.text,
	        x: 'center',
	        y: 'center',
	        textStyle : {
	            textAlign:'center',
	            color : '#fff',
	            fontFamily : '微软雅黑',
	            fontSize : 20
	        }
	    },
	    tooltip: {
	       show:false,
	        trigger: 'item',
	        formatter: "{a} <br/>{b}: {c} ({d}%)"
	    },
	    series: [
	        {
	            type:'pie',
	            radius: ['70%', '80%'],
	            avoidLabelOverlap: false,
	            hoverAnimation:false,
	            silent:true,
	            label: {
	                normal: {
	                    show: false,
	                    position: 'center',
	                    textStyle:{
	                        fontSize:40,
	                        color:'green'
	                    }
	                },
	                emphasis: {
	                    show: true,
	                    textStyle: {
	                        fontSize: '14',
	                        fontWeight: 'bold',
	                        color:'#fff'
	                    }
	                }
	            },
	            labelLine: {
	                normal: {
	                    show: false
	                }
	            },
	            data:rdData.data,
	            itemStyle:{
	                normal:{
	                    color: function(params) {
	                        // build a color map as your need.
	                        var colorList = rdData.colors;
	                        return colorList[params.dataIndex];
	                    }
	                }
	            }
	        }
	    ]
	};
	chartObj.setOption(option);
}

function drawLineChart(chartObj){
	var option = {
	    tooltip: {
	        trigger: 'axis'
	    },
	    legend: {
	    	textStyle:{
	    		color:"#fff"
	    	},
	        data:['死亡率','并发症发生率','再手术率','再住院率']
	    },
	   
	    xAxis:  {
	        type: 'category',
	        boundaryGap: false,
	        axisLine: {
	            lineStyle: {
	                color: '#fff'
	            }
	        },
	        axisLabel:{
	        	interval:0,  
	         	rotate: 45
	        },
	        data: ['心胸外科','泌尿外科','肛肠科','整形外科','神经外科','骨科','普通外科']
	    },
	    yAxis: {
	        type: 'value',
	        axisLine: {
	            lineStyle: {
	                color: '#fff'
	            }
	        },
	        axisLabel: {
	            formatter: '{value}%'
	        }
	    },
	    series: [
	        {
	            name:'死亡率',
	            type:'line',
	            itemStyle:{
	            	normal:{
	            		color:"#bbff4d"
	            	}
	            },
	            data:[20, 11, 15, 13, 12, 13, 10]
	        },
	        {
	            name:'并发症发生率',
	            type:'line',
	            itemStyle:{
	            	normal:{
	            		color:"#f9a6ff"
	            	}
	            },
	            data:[11, 12, 9, 13, 7, 9, 10]	            
	        },
	        {
	            name:'再手术率',
	            type:'line',
	            itemStyle:{
	            	normal:{
	            		color:"#f70a62"
	            	}
	            },
	            data:[7, 5, 12, 8, 10, 9, 11]	            
	        },
	        {
	            name:'再住院率',
	            type:'line',
	            itemStyle:{
	            	normal:{
	            		color:"#47c7d4"
	            	}
	            },
	            data:[12, 14, 9, 7, 8, 10, 6]	            
	        }
	    ]
	};
	chartObj.setOption(option);
}

function drawChart9(c9){
	var option = {
	    tooltip : {
	        trigger: 'item',
	        formatter: "{a} <br/>{b} : {c} ({d}%)"
	    },
	    legend: {
	        orient: 'horizontal',
	        left: 'left',
	        textStyle:{
	    		color:"#fff",
	    		fontSize:'12px'
	    	},
	        data: ['新生儿患者','急诊科危重','住院手术']
	    },
	    series : [
	        {
	            name: '住院死亡率',
	            type: 'pie',
	            radius : '80%',
	            center: ['50%', '60%'],
	            label: {
	                normal: {
	                    position: 'inner'
	                }
	            },
	            labelLine: {
	                normal: {
	                    show: false
	                }
	            },
	            data:[
	                {value:435, name:'新生儿患者'},
	                {value:234, name:'急诊科危重'},
	                {value:270, name:'住院手术'}
	            ],
	            itemStyle: {
	                emphasis: {
	                    shadowBlur: 10,
	                    shadowOffsetX: 0,
	                    shadowColor: 'rgba(0, 0, 0, 0.5)'
	                },
	                normal:{
	                    color: function(params) {
	                        // build a color map as your need.
	                        var colorList = ['#3EAA74','#B2522E','#17769D'];
	                        return colorList[params.dataIndex];
	                    }
	                }
	            }
	        }
	    ]
	};
	c9.setOption(option);
}


/*
	setChartHeight() 计算图表的高度
	参数row代表区块
	参数chart代表区块中的图表
 * */
function setChartHeight(row,chart){
	var rowHeight = $(row).height();
	var infoHeight = $("#mm").outerHeight(true);
	var rowFluidHeight = rowHeight - infoHeight - 10;  //10像素margin-bottom
	$(".box" , row).height(rowFluidHeight / 2);
	var chartHeight = rowFluidHeight / 2 + "px";
	$(chart).height(chartHeight);
}

/*
	setTbodyHeight() 计算表格的高度
	参数row代表区块
	参数tableTitle代表表格名称，一个h4标签
	参数tbody代表表格内容区域
 * */
function setTbodyHeight(row,tableTitle,tbody){
	var rowHeight = $(row).height();
	var tableTitleHeight = $(tableTitle).outerHeight(true);
	var theadHeight = $(row).find(".t-head").outerHeight(true);
	var tbodyHeight = rowHeight - tableTitleHeight - theadHeight - 5 + "px";    //这里减了一个5像素
	$(tbody).css("height",tbodyHeight);
}


$(function(){
//	几个圆环
	var rdData1 = {
		text : '83%', 
		data:[
			{value:482, name:'外科'},
            {value:220, name:'其他科室'}
	    ],
	    colors:['#ff8888','#7A7A7A']
	};
	var rdData2 = {
		text : '76%', 
		data:[
			{value:334, name:'内科'},
            {value:210, name:'其他科室'}
	    ],
	    colors:['#e6ff99','#7A7A7A']
	};
	var rdData3 = {
		text : '70%', 
		data:[
			{value:289, name:'儿科'},
            {value:190, name:'其他科室'}
	    ],
	    colors:['#a6ff6e','#7A7A7A']
	};
	var rdData4 = {
		text : '66%', 
		data:[
			{value:141, name:'妇科'},
            {value:90, name:'其他科室'}
	    ],
	    colors:['#c06dff','#7A7A7A']
	};
	
	setChartHeight("#row3","#chart1");
	setChartHeight("#row3","#chart2");
	
	setTbodyHeight("#row4","#tableTitle1","#tBody1");
	setTbodyHeight("#row4","#tableTitle2","#tBody2");
	
	var c1 = echarts.init(document.getElementById("chart1"));
	var c2 = echarts.init(document.getElementById("chart2"));
	var c3 = echarts.init(document.getElementById("chart3"));
	var c4 = echarts.init(document.getElementById("chart4"));
	var c5 = echarts.init(document.getElementById("chart5"));
	var c6 = echarts.init(document.getElementById("chart6"));
	var c7 = echarts.init(document.getElementById("chart7"));
	var c8 = echarts.init(document.getElementById("chart8"));
	var c9 = echarts.init(document.getElementById("chart9"));
	
	drawChart1(c1);
	drawChart2(c2);
	drawChart3(c3);
	drawRadiusChart(c4,rdData1);
	drawRadiusChart(c5,rdData2);
	drawRadiusChart(c6,rdData3);
	drawRadiusChart(c7,rdData4);
	drawLineChart(c8);
	drawChart9(c9);
	
});
